<extend name="Public/base"/>

<block name="body">
	<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
	<!--<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>-->
	<div class="main-title">
		<h2>编辑音乐</h2>
	</div>
	<div class="tab-wrap">
		<ul class="tab-nav nav">
			<li data-tab="tab1" class="current"><a href="javascript:void(0);">基 础</a></li>
		</ul>
		<div class="tab-content">
			<!--<form action="{:U()}" method="post" class="form-horizontal">-->
			<!-- 基础 -->
			<div class="box_input" style="margin-bottom: 20px;">

				<form action="{:U('Music_edit')}" method="post"  enctype="multipart/form-data" class="form-horizontal">

					<div id="tab1" class="tab-pane in tab1">
						<div class="form-item">
							<label class="item-label">
								音乐名<span class="check-tips">（音乐名不能为空）</span>
							</label>
							<div class="controls">
								<input type="text" name="title"  class="text input-large" value="{$info.title|default=''}">
							</div>
						</div>

						<input type="hidden" name="id"  class="text input-large" value="{$info.id}">

						<div class="controls">
							<label class="item-label">原唱</label>
							<input type="file" id="upload_video">
							<input type="hidden" name="yc_url" id="videourl" value="{$info['yc_url']}"/>
							<div class="upload-video-box">
								<notempty name="info['yc_url']">
									<audio src="{$info['yc_url']}" controls="controls" style="width: 120px; height: 120px;"></audio>
								</notempty>
							</div>
						</div>


						<div class="controls">
							<label class="item-label">伴奏</label>
							<input type="file" id="upload_videobz">
							<input type="hidden" name="bz_url" id="videourlbz" value="{$info['bz_url']}"/>
							<div class="upload-video-box1">
								<notempty name="info['bz_url']">
									<audio src="http://zhibo.com/{$info['bz_url']}" controls="controls" style="width: 120px; height: 120px;"></audio>
								</notempty>
							</div>
						</div>



						<script type="text/javascript">
							//上传音乐
							/* 初始化上传插件 */
							$("#upload_video").uploadify({
								"height"          : 30,
								"swf"             : "__STATIC__/uploadify/uploadify.swf",
								"fileObjName"     : "download",
								"buttonText"      : "上传音乐",
								"uploader"        : "{:U('File/uploadMusic',array('session_id'=>session_id()))}",
								"width"           : 120,
								'removeTimeout'   : 1,
								'fileTypeExts'    : '*.mp3',
								"onUploadSuccess" : uploadVideo,
								'onFallback' : function() {
									alert('未检测到兼容版本的Flash.');
								}
							});
							function uploadVideo(file, data){

								var data = $.parseJSON(data);
								var src = '';
								if(data.status){
									src = '__ROOT__' + data.path;
									$("#videourl").val(src);
									$(".upload-video-box").html('<audio src="'+src+'" controls="controls" style="width: 120px; height: 120px;"></audio>');
								} else {
									updateAlert(data.info);
								}
							}

							//上传音乐
							/* 初始化上传插件 */
							$("#upload_videobz").uploadify({
								"height"          : 30,
								"swf"             : "__STATIC__/uploadify/uploadify.swf",
								"fileObjName"     : "download",
								"buttonText"      : "上传音乐",
								"uploader"        : "{:U('File/uploadMusic',array('session_id'=>session_id()))}",
								"width"           : 120,
								'removeTimeout'   : 1,
								'fileTypeExts'    : '*.mp3',
								"onUploadSuccess" : uploadVideo1,
								'onFallback' : function() {
									alert('未检测到兼容版本的Flash.');
								}
							});
							function uploadVideo1(file, data){
								var data = $.parseJSON(data);
								var src = '';
								if(data.status){
									src = '__ROOT__' + data.path;
									$("#videourlbz").val(src);
									$(".upload-video-box1").html('<audio src="'+src+'" controls="controls" style="width: 120px; height: 120px;"></audio>');
								} else {
									updateAlert(data.info);
								}
							}
						</script>
						<input type="submit" id="mp3_submit" class="btn submit-btn" type="button" value="提交"/>
						<button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
						<!--<button type="submit" id="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定</button>-->
				</form>

			</div>
			<!--</form>-->
		</div>
	</div>
</block>

<block name="script">
	<script>
		//录音上传
		$(function () {
			$("#test").change(function () {
				var objUrl = getObjectURL(this.files[0]);
				$("#audio").attr("src", objUrl);
				$("#audio")[0].pause();
				$("#audio").show();
				$("#mp3_submit").show()
				getTime();

			});
		});
		<!--获取mp3文件的时间 兼容浏览器-->
		function getTime() {
			setTimeout(function () {
				var duration = $("#audio")[0].duration;
				if(isNaN(duration)){
					getTime();
				}
				else{
					console.info("该歌曲的总时间为："+$("#audio")[0].duration+"秒")
				}
			}, 10);
		}
		<!--把文件转换成可读URL-->
		function getObjectURL(file) {
			var url = null;
			if (window.createObjectURL != undefined) { // basic
				url = window.createObjectURL(file);
			} else if (window.URL != undefined) { // mozilla(firefox)
				url = window.URL.createObjectURL(file);
			} else if (window.webkitURL != undefined) { // webkit or chrome
				url = window.webkitURL.createObjectURL(file);
			}
			return url;

		}
	</script>
	<script type="text/javascript">
		$(function(){
			showTab();
			$("input[name=reply]").change(function(){
				var $reply = $(".form-item.reply");
				parseInt(this.value) ? $reply.show() : $reply.hide();
			}).filter(":checked").change();
		});
		//导航高亮
		highlight_subnav('{:U('Manage/music')}');
	</script>
</block>